package com.yckj.dao;

import cn.hutool.crypto.SecureUtil;
import com.yckj.util.DbUtilHikari;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 对用户表操作
 * @author xuanl
 * @version 1.0
 * 注册成功返回1，否则返回0*/
public class UserDao {
    public int insertUser(String uname, String upsw) throws SQLException {
        /**声明变量被用*/
        //数据库连接
        Connection conn = null;
        //执行sql语句
        PreparedStatement pstmt= null;
        int flag;
        //获取链接
        conn = DbUtilHikari.getConnection();
        //定义并准备sql语句
      /*  String sqlL ="INSERT INTO users(username,userpsw) VALUES('','')";*/
        String sql = "INSERT INTO users(username,userpsw) VALUES(?,?)";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1,uname);
            pstmt.setString(2, SecureUtil.md5(upsw));
        flag=  pstmt.executeUpdate();
            //关闭数据库资源
         DbUtilHikari.close(pstmt,conn);
        return flag;
    }
}
